function savepbm(Filename, Matrix)

%A = round(rand(6,7)*9)  % Write this to file.
fid = fopen(Filename,'wt');
[M N] = size(Matrix);

for m=1:M
    for n=1:N
        if(Matrix(m,n)>0.5)
            Matrix(m,n)=1;
        end
    end
end
    

fprintf(fid,'P1\n');
fprintf(fid,['# ' Filename '\n']);
fprintf(fid,'%g ', [M N]);
fprintf(fid,'\n');
for ii = 1:size(Matrix,1)
    fprintf(fid,'%g ',Matrix(ii,:));
    fprintf(fid,'\n');
end
fclose(fid);
